-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Proposal: Proper exponential backoff with jitter #9390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+1
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit turns the default backoff method into a true exponential backoff algorithm, where we introduce jitter in order to reduce the thundering-herds problem.
yeah we’ve had this discussion before:
I’m not against this per se, but maybe we shouldn’t do this in a minor version 🤔
Ya, it being in a major version makes sense to me
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I would like to propose a change to the default retry logic. Currently, the retry logic is a static number based on number of retries. This might work for simple cases, but leads to a thundering herds problem.
Essentially, let's say that our requests failed because we made too many requests to the backend at once. We could get 5xx's from the server because of capacity. If we delay all requests by the same number, we are likely to get stuck in an infinite cycle of overloading the server.
Industry practice is typically to introduce jitter so that a request happens at a random interval between 10ms and the exponential time. This prevents the thundering herds problem.
As a more complex case, say that 20 different users get a webhook notification at the same time, and they all use tanstack query to hit the server api at the same time. Due to capacity issues, they all get 5xx's. Even if tanstack query is rate limiting for a single user, it can't do it across multiple clients. The clients will all fail, and will all "retry" at the same time, because they will all have the same static retry logic.
This PR proposes to change the default to a random interval from 10ms up to the existing exponential limit.
However, I realize that changing defaults like this can potentially lead to weird changes for users of the library, so I fully understand if this proposal gets rejected. I can always override the delay function for myself, but thought I would propose a better default if there is appetite. Thoughts?